package com.xiaoying.server.publish.impl;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import redis.clients.jedis.Jedis;

import com.xiaoying.server.publish.entity.FileInfo;
import com.xiaoying.server.publish.entity.UploadResult;
import com.xiaoying.server.publish.upload.UploadFile;
import com.xiaoying.server.publish.utils.RedisUtil;


/**
 * 上传文件成功或者失败次数过多时，产出处理结果
 * 处理结果入库，异步移除Redis备份队列
 * @author ZJD
 *
 */
public class BackupUploadInfoHandler implements Runnable {
	private static Log log = LogFactory.getFactory().getInstance(BackupUploadInfoHandler.class);
	
	private Jedis redis;
	private BlockingQueue<String> redisBackupQueue;
	
	public void handler(BlockingQueue<String> redisBackupQueue){
		this.redisBackupQueue = redisBackupQueue;
        Thread proc = new Thread(this);
        proc.start();
	}
	
	@Override
	public void run() {
		String key = null;
		while(true){			
			try {
				key = this.redisBackupQueue.take();				
				// 获取处理备份的redis客户端
				redis = RedisUtil.getBackupRedisInstance();
				if(key != null){
					redis.del(key);
//					log.debug(key+" Redis上传备份消息删除成功!!!");
					System.out.println(key+" Redis上传备份消息删除成功!!!");
				}else{
					log.error(key+" Redis上传备份消息删除失败!!!");
				}				
			} catch (InterruptedException e) {
				log.error(e);
			}
		}

	}
	

}
